/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for CS_OrderHistoryDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class CS_OrderHistoryDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public CS_OrderHistoryDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(CS_OrderHistoryDO objCS_OrderHistoryDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCS_OrderHistory_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objCS_OrderHistoryDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@UserId", SqlDbType.Int);
            Sqlparam.Value = objCS_OrderHistoryDO.UserId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Action", SqlDbType.NVarChar);
            Sqlparam.Value = objCS_OrderHistoryDO.Action;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreateDate", SqlDbType.DateTime);
            Sqlparam.Value = objCS_OrderHistoryDO.CreateDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NVarChar);
            Sqlparam.Value = objCS_OrderHistoryDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IP", SqlDbType.NVarChar);
            Sqlparam.Value = objCS_OrderHistoryDO.IP;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Contents", SqlDbType.NVarChar);
            Sqlparam.Value = objCS_OrderHistoryDO.Contents;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(CS_OrderHistoryDO objCS_OrderHistoryDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCS_OrderHistory_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@OrderHistoryId", SqlDbType.Int);
            Sqlparam.Value = objCS_OrderHistoryDO.OrderHistoryId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objCS_OrderHistoryDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@UserId", SqlDbType.Int);
            Sqlparam.Value = objCS_OrderHistoryDO.UserId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Action", SqlDbType.NVarChar);
            Sqlparam.Value = objCS_OrderHistoryDO.Action;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreateDate", SqlDbType.DateTime);
            Sqlparam.Value = objCS_OrderHistoryDO.CreateDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NVarChar);
            Sqlparam.Value = objCS_OrderHistoryDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IP", SqlDbType.NVarChar);
            Sqlparam.Value = objCS_OrderHistoryDO.IP;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Contents", SqlDbType.NVarChar);
            Sqlparam.Value = objCS_OrderHistoryDO.Contents;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(CS_OrderHistoryDO objCS_OrderHistoryDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCS_OrderHistory_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@OrderHistoryId", SqlDbType.Int);
            Sqlparam.Value = objCS_OrderHistoryDO.OrderHistoryId;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCS_OrderHistory_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public CS_OrderHistoryDO Select(CS_OrderHistoryDO objCS_OrderHistoryDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCS_OrderHistory_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@OrderHistoryId", SqlDbType.Int);
            Sqlparam.Value = objCS_OrderHistoryDO.OrderHistoryId;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["OrderHistoryId"]))
                    objCS_OrderHistoryDO.OrderHistoryId = Convert.ToInt32(dr["OrderHistoryId"]);
                if (!Convert.IsDBNull(dr["OrderId"]))
                    objCS_OrderHistoryDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                if (!Convert.IsDBNull(dr["UserId"]))
                    objCS_OrderHistoryDO.UserId = Convert.ToInt32(dr["UserId"]);
                if (!Convert.IsDBNull(dr["Action"]))
                    objCS_OrderHistoryDO.Action = Convert.ToString(dr["Action"]);
                if (!Convert.IsDBNull(dr["CreateDate"]))
                    objCS_OrderHistoryDO.CreateDate = Convert.ToDateTime(dr["CreateDate"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objCS_OrderHistoryDO.Note = Convert.ToString(dr["Note"]);
                if (!Convert.IsDBNull(dr["IP"]))
                    objCS_OrderHistoryDO.IP = Convert.ToString(dr["IP"]);
                if (!Convert.IsDBNull(dr["Contents"]))
                    objCS_OrderHistoryDO.Contents = Convert.ToString(dr["Contents"]);

            }
            return objCS_OrderHistoryDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCS_OrderHistory_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrCS_OrderHistoryDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    CS_OrderHistoryDO objCS_OrderHistoryDO = new CS_OrderHistoryDO();
                    if (!Convert.IsDBNull(dr["OrderHistoryId"]))
                        objCS_OrderHistoryDO.OrderHistoryId = Convert.ToInt32(dr["OrderHistoryId"]);
                    if (!Convert.IsDBNull(dr["OrderId"]))
                        objCS_OrderHistoryDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                    if (!Convert.IsDBNull(dr["UserId"]))
                        objCS_OrderHistoryDO.UserId = Convert.ToInt32(dr["UserId"]);
                    if (!Convert.IsDBNull(dr["Action"]))
                        objCS_OrderHistoryDO.Action = Convert.ToString(dr["Action"]);
                    if (!Convert.IsDBNull(dr["CreateDate"]))
                        objCS_OrderHistoryDO.CreateDate = Convert.ToDateTime(dr["CreateDate"]);
                    if (!Convert.IsDBNull(dr["Note"]))
                        objCS_OrderHistoryDO.Note = Convert.ToString(dr["Note"]);
                    if (!Convert.IsDBNull(dr["IP"]))
                        objCS_OrderHistoryDO.IP = Convert.ToString(dr["IP"]);
                    if (!Convert.IsDBNull(dr["Contents"]))
                        objCS_OrderHistoryDO.Contents = Convert.ToString(dr["Contents"]);
                    arrCS_OrderHistoryDO.Add(objCS_OrderHistoryDO);
                }
            }
            return arrCS_OrderHistoryDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCS_OrderHistory_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable GetByOrder(int orderId)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spCS_OrderHistory_GetByOrder";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = orderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        #endregion

    }

}
